<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <title>vue.draggable group例子</title>
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, minimal-ui">
    <script src="https://www.itxst.com/package/vue/vue.min.js"></script>
    <script src="https://www.itxst.com/package/sortable/Sortable.min.js"></script>
    <script src="https://www.itxst.com/package/vuedraggable/vuedraggable.umd.min.js"></script>
    <style>
        /*定义要拖拽元素的样式*/
        .ghostClass {
            background-color: blue !important;
        }

        .chosenClass {
            background-color: red !important;
            opacity: 1 !important;
        }

        .dragClass {
            background-color: blueviolet !important;
            opacity: 1 !important;
            box-shadow: none !important;
            outline: none !important;
            background-image: none !important;
        }

        .itxst {
            margin: 10px;
        }

        .title {
            padding: 6px 12px;
        }

        .col {
            width: 40%;
            flex: 1;
            padding: 10px;
            border: solid 1px #eee;
            border-radius: 5px;
            float: left;
        }

        .col+.col {
            margin-left: 10px;
        }

        .item {
            padding: 6px 12px;
            margin: 0px 10px 0px 10px;
            border: solid 1px #eee;
            background-color: #f1f1f1;
        }

        .item:hover {
            background-color: #fdfdfd;
            cursor: move;
        }

        .item+.item {
            border-top: none;
            margin-top: 6px;
        }
    </style>
</head>

<body style="padding:10px;">
    <div id="app">
        <!--使用draggable组件-->
        <div class="itxst">
            <div class="col">
                <div class="title">A列</div>
                <draggable :list="arr1" :group="{name:'row',pull:'clone',sort:'false'}" :sort='false' animation="300" dragClass="dragClass" ghostClass="ghostClass"
                    chosenClass="chosenClass" @start="onStart" :move='move'>
                    <transition-group>
                        <div class="item" v-for="item in arr1" :key="item.id">{{item.name}}</div>
                    </transition-group>
                </draggable>
            </div>
            <div class="col">
                <div class="title">B列</div>
                <draggable :list="arr2" :group="{name:'row',pull:false,sort:'false'}" animation="100" dragClass="dragClass" ghostClass="ghostClass" style="padding:10px"
                    chosenClass="chosenClass" @add="(e) => addFieldByDrag(e,arr2)">
                    <transition-group>
                        <div class="item" v-for="item in arr2" :key="item.id">{{item.name}}</div>
                    </transition-group>
                </draggable>
            </div>
        </div>
    </div>
    <script>
        // debugger;
        Vue.component('vuedraggable', window.vuedraggable.name)
        var app = new Vue({
            el: '#app',
            components: {
                vuedraggable,
            },
            data() {
                return {
                    obj: {},
                    arr1: [{
                            id: 1,
                            name: 'www.itxst.com'
                        },
                        {
                            id: 2,
                            name: 'www.jd.com'
                        }
                    ],
                    arr2: [],// 不是空的不能拖，而是要放的那个拖拽容器必须要有高度

                };
            },
            methods: {
                onStart(e) {
                    const oldIndex = e.oldIndex;
                    this.obj = this.arr1[oldIndex];
                    console.log(this.obj)
                },
                move(e){
                    console.log(e);
                    return true;
                },
                addFieldByDrag(e, list){
                    console.log(e)
                    console.log(list)
                }
            }
        });
    </script>
</body>

</html>